package com.flight.trans.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.flight.trans.R;
import com.flight.trans.adapter.LeavePortWarehousingGoodsAdapter;
import com.flight.trans.adapter.LevePortWarehousingInfoAdapter;
import com.flight.trans.bean.TugBean.TugData;
import com.flight.trans.bean.LeavePortWarehousingDetailBean.WarehousingDetailData;
import com.flight.trans.bean.LeavePortWarehousingDetailBean.WarehousingDetailData.OutwardStorageData;
import com.flight.trans.bean.LeavePortWarehousingDetailBean.WarehousingDetailData.WarehousingMainInfoBean;
import com.flight.trans.bean.LeavePortWarehousingDetailBean.WarehousingDetailData.WarehousingMainInfoBean.MainInfoDetail;
import com.flight.trans.bean.NfcBean;
import com.flight.trans.bean.StorageAreaBean.StorageAreaData;
import com.flight.trans.bean.ChannelBean.ChannelData;
import com.flight.trans.bean.ContainerBean.ContainerData;
import com.flight.trans.global.Constant;
import com.flight.trans.global.ConstantInfo;
import com.flight.trans.http.NetworkUtils;
import com.flight.trans.http.network.OkGoBackListener;
import com.flight.trans.listener.OnItemClickListener;
import com.flight.trans.listener.OnSheetItemClickListener;
import com.flight.trans.listener.OnTextClickListener;
import com.flight.trans.util.CommonUtils;
import com.flight.trans.util.JsonUtils;
import com.flight.trans.view.dialog.AlertDialog;
import com.flight.trans.view.dialog.BottomDialog;
import com.flight.trans.view.dialog.ChanelDialog;
import com.flight.trans.view.dialog.ContainerDialog;
import com.flight.trans.view.dialog.TugDialog;
import com.flight.trans.view.dialog.StorageAreaDialog;
import com.flight.trans.view.edit.CustomContainerEditorActivity;
import com.flight.trans.view.edit.EditorActivity;
import com.flight.trans.view.edit.GoodsEditorActivity;
import com.flight.trans.base.BaseActivity;
import com.flight.trans.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 出港入库
 */
public class LeavePortWarehousingDetailsActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout mLlContainer ;
    private LinearLayout mLlTitleContainer ;
    private TextView mTvTitleName ;//标题
    private Button mBtnSubmit ,//提交
            mBtnRevise ,//修改
            mBtnSave ;//保存
    private TextView mTvOrderNo,//货邮单号
            mTvFlightDate ,//航班日期
            mTvFlightNumber ,//航班号
            mTvActShape ,//宽窄体
            mTvETD ,//预起时间
            mTvDestination ,//目的站
            mTvProductName ,//品名
            mTvOrderCount ,//运单件数
            mTvFloorCapacity ,//地板承受力
            mTvRemarks ;//备注
    private RecyclerView mRlContainerGoods ;
    private TextView mTvCheckChannel ,//地磅通道
            mTvGoodsWeight,//货物重量
            mTvStorageArea ,//存放区域
            mTvContainerType ,//容器类型
            mTvWarehousedText ,//入库情况文字
            mTvWarehoused ;//入库情况
    private ImageButton mIbStorageAreaNFC,//存放区域
            mIbBridgeWeigh ,//货物重量
            mIbContainerNoNFC ,//容器编号
            mIbPalletNoNFC;//托盘编号
    private TextView mTvGoodsTotalWeight ,//货物总重
            mTvContainerWeight ,//容器重量
            mTvPalletWeight ;//托盘重量
    private TextView mTvContainerNo ,//容器编号
            mTvPalletNo ;//托盘编号
    private LinearLayout mLlWarehousedContainer,//入库情况
            mLlPalletNoContainer ;//托盘容器

    private WarehousingDetailData mWarehousingDetailData ;
    private OutwardStorageData mOrderDetail;

    private RecyclerView mRlContainerInfo ;
    private LevePortWarehousingInfoAdapter warehousingMainInfoAdapter;
    private List<WarehousingMainInfoBean> warehousingMainInfoList ;//入库信息集合

    private LeavePortWarehousingGoodsAdapter leavePortWarehousingGoodsAdapter ;
    private List<MainInfoDetail> mainInfoDetailList ;//货物信息

    private List<TugData> mOtherGoodsContainerList ;

    // 选中的通道
    private List<ChannelData> mChannelDataList ;
    private ChannelData mChannelData;
    // 选中的容器，托盘
    private TugData mTugData, mPalletData;
    // 集装器
    private ContainerData mContainerData;

    private boolean isBridgeWight ;// 是否为地磅获取的重量
    private double mContainerWeight ,// 容器重量
        mGoodsTotalWeight,// 货物毛重
        mGoodsWeight ;//货物净重

    // 选中的区域
    private StorageAreaData mStorageAreaData ;
    private String mActShape ;

    // 运单ID
    private int mOrderID , mBizOrderDetailId;
    private int ContainerType = 1;

    private int clickInfoPosition = -1 ;

    @Override
    protected int setContentView() {
        return ConstantInfo.notNW ? R.layout.activity_leave_port_warehousing_details : R.layout.activity_leave_port_warehousing_details_nw;
    }

    @Override
    protected void initView() {
        mLlContainer = findViewById(R.id.mLlContainer);
        mLlTitleContainer = findViewById(R.id.mLlTitleContainer);
        mTvTitleName = findViewById(R.id.mTvTitleName);

        mBtnSave = findViewById(R.id.mBtnSave);
        mBtnSubmit = findViewById(R.id.mBtnSubmit);
        mBtnRevise = findViewById(R.id.mBtnRevise);

        mTvOrderNo = findViewById(R.id.mTvOrderNo);
        mTvFlightDate = findViewById(R.id.mTvFlightDate);
        mTvFlightNumber = findViewById(R.id.mTvFlightNumber);
        mTvActShape = findViewById(R.id.mTvActShape);
        mTvETD = findViewById(R.id.mTvETD);
        mTvDestination = findViewById(R.id.mTvDestination);
        mTvProductName = findViewById(R.id.mTvProductName);
        mTvOrderCount = findViewById(R.id.mTvOrderCount);
        mTvFloorCapacity = findViewById(R.id.mTvFloorCapacity);
        mTvRemarks = findViewById(R.id.mTvRemarks);

        mRlContainerGoods = findViewById(R.id.mRlContainerGoods);
        mTvGoodsWeight = findViewById(R.id.mTvGoodsWeight);
        mTvCheckChannel = findViewById(R.id.mTvCheckChannel);
        mTvStorageArea = findViewById(R.id.mTvStorageArea);
        mTvContainerType = findViewById(R.id.mTvContainerType);
        mTvWarehousedText = findViewById(R.id.mTvWarehousedText);
        mTvWarehoused = findViewById(R.id.mTvWarehoused);

        mTvContainerNo = findViewById(R.id.mTvContainerNo);
        mTvPalletNo = findViewById(R.id.mTvPalletNo);

        mTvGoodsTotalWeight = findViewById(R.id.mTvGoodsTotalWeight);
        mTvContainerWeight = findViewById(R.id.mTvContainerWeight);
        mTvPalletWeight = findViewById(R.id.mTvPalletWeight);

        mLlWarehousedContainer = findViewById(R.id.mLlWarehousedContainer);
        mLlPalletNoContainer = findViewById(R.id.mLlPalletNoContainer);

        mIbStorageAreaNFC = findViewById(R.id.mIbStorageAreaNFC);
        mIbBridgeWeigh = findViewById(R.id.mIbBridgeWeigh);
        mIbContainerNoNFC = findViewById(R.id.mIbContainerNoNFC);
        mIbPalletNoNFC = findViewById(R.id.mIbPalletNoNFC);

        mRlContainerInfo = findViewById(R.id.mRlContainerInfo);
    }

    @Override
    protected void initData() {
        IsEditor = mBundle.getBoolean(Constant.IsEditor);
        mOrderID = mBundle.getInt(Constant.ID);
        mBizOrderDetailId = mBundle.getInt(Constant.BIZ_ORDER_DETAIL_ID);
        mActShape = mBundle.getString(Constant.ACT_SHAPE);

        CommonUtils.setScreenContainerPaddingTop(mLlContainer);
        CommonUtils.setScreenViewVisible(mLlTitleContainer);

        mTvTitleName.setText(getString(R.string.title_leave_port_warehousing));
        CommonUtils.onFinishTouch(mActivity , mLlContainer);
    }

    @Override
    protected void initConnect() {
        NetworkUtils.getLeavePortWarehousingDetails(new OkGoBackListener(mActivity) {
            @Override
            public void onSuccess(Object body) {
                mWarehousingDetailData = (WarehousingDetailData) body;

                // 初始化当前航班的其他容器
                initContainer();

                // 赋值运单信息
                setOrderInfo();
            }
        }, mBizOrderDetailId);
    }

    /**
     * 初始化
     */
    private void setOrderInfo(){
        if(mWarehousingDetailData == null)
            return;

        mOrderDetail = mWarehousingDetailData.getOutwardStorageData();

        if(mOrderDetail == null)
            return;

        if(IsEditor && ConstantInfo.WIDE_BODY.equals(mActShape))
            AlertDialog.getInstance(mActivity)
                    .setContent(R.string.dialog_wide_body)
                    .setSingleButton()
                    .show();

        mChannelDataList = mOrderDetail.getChannelList();
        mChannelData = (mChannelDataList != null && mChannelDataList.size() != 0) ? mChannelDataList.get(0) : null;

        mTvOrderNo.setText(mOrderDetail.getOrderNo());//货邮单号
        mTvFlightDate.setText(mOrderDetail.getFldt());//航班日期
        mTvFlightNumber.setText(mOrderDetail.getFlightNo());//航班号
        mTvETD.setText(CommonUtils.getTimeNorm(mOrderDetail.getEtd()));//预起时间
        mTvDestination.setText(mOrderDetail.getDeap() + " / " + mOrderDetail.getDeapStr());//目的站
        mTvProductName.setText(mOrderDetail.getTradeName());//品名
        mTvOrderCount.setText(String.valueOf(mOrderDetail.getNum()));//运单件数
        mTvFloorCapacity.setText(String.valueOf(mOrderDetail.getFloorCapacity()));
        mTvRemarks.setText(!TextUtils.isEmpty(mOrderDetail.getRemark()) ? mOrderDetail.getRemark() : getString(R.string.text_not));//备注

        mTvActShape.setVisibility(ConstantInfo.WIDE_BODY.equals(mActShape) ? View.VISIBLE : View.GONE);

        // 拖斗信息
        mTvContainerType.setText(getString(R.string.text_tug));
        // 入库件数重量信息
        mTvWarehoused.setText(getString(R.string.text_no_warehousing_good));
        // 通道
        mTvCheckChannel.setText(mChannelData != null ? mChannelData.getName() : "");

        warehousingMainInfoList = mWarehousingDetailData.getMainList();

        // 初始化本地信息
        initLocationData();
    }

    private void initLocationData(){
        mIbStorageAreaNFC.setVisibility(IsEditor ? View.VISIBLE : View.GONE);
        mIbContainerNoNFC.setVisibility(IsEditor ? View.VISIBLE : View.GONE);
        mIbPalletNoNFC.setVisibility(IsEditor ? View.VISIBLE : View.GONE);
        mIbBridgeWeigh.setVisibility(IsEditor ? View.VISIBLE : View.GONE);

        if(IsEditor){
            mBtnSubmit.setVisibility(View.VISIBLE);
            mBtnSave.setVisibility(View.VISIBLE);
            mBtnRevise.setVisibility(View.GONE);
            mTvCheckChannel.setOnClickListener(this);
            mTvStorageArea.setOnClickListener(this);
            mTvContainerType.setOnClickListener(this);
            mIbStorageAreaNFC.setOnClickListener(this);
            mIbContainerNoNFC.setOnClickListener(this);
            mIbPalletNoNFC.setOnClickListener(this);
            if(ConstantInfo.mPermissionsList.contains(Constant.CGRK_MODIFY) || ConstantInfo.IS_ADMIN)
                mTvGoodsWeight.setOnClickListener(this);
            mIbBridgeWeigh.setOnClickListener(this);
            mTvContainerNo.setOnClickListener(this);
            mTvPalletNo.setOnClickListener(this);
        }else {
            mBtnSave.setVisibility(View.GONE);
            mBtnSubmit.setVisibility(View.GONE);
            mBtnRevise.setVisibility(mOrderDetail.getState() == Constant.StatusLeaveWarehousing ? View.VISIBLE : View.GONE);
        }

        // 赋值板上货物，初始为空
        initGoodsAdapter();
    }

    /**
     * 拖斗信息
     */
    private void initGoodsAdapter(){
        if(mainInfoDetailList == null || mainInfoDetailList.size() == 0) {
            mainInfoDetailList = new ArrayList<>();
            MainInfoDetail mainInfoDetail = new MainInfoDetail();
            mainInfoDetail.setDetailLength(mOrderDetail.getCustomDetailLength()/100);
            mainInfoDetail.setDetailWidth(mOrderDetail.getCustomDetailWidth()/100);
            mainInfoDetail.setDetailHeight(mOrderDetail.getCustomDetailHeight()/100);
            if(warehousingMainInfoList == null || warehousingMainInfoList.size() == 0)
                mainInfoDetail.setDetailNumber(mOrderDetail.getNum());
            mainInfoDetailList.add(mainInfoDetail);
            mainInfoDetailList.add(null);
        }

        if(mainInfoDetailList.get(mainInfoDetailList.size() -1 ) != null && IsEditor)
            mainInfoDetailList.add(null);

        if(leavePortWarehousingGoodsAdapter == null){
            leavePortWarehousingGoodsAdapter = new LeavePortWarehousingGoodsAdapter(mActivity , mainInfoDetailList , IsEditor);
            mRlContainerGoods.setAdapter(leavePortWarehousingGoodsAdapter);
            mRlContainerGoods.setLayoutManager(new LinearLayoutManager(mActivity));

            leavePortWarehousingGoodsAdapter.setEditorCallbackListener(new GoodsEditorCallbackListener());
            leavePortWarehousingGoodsAdapter.setOnTextClickListener(new GoodsItemTextClickListener());
            leavePortWarehousingGoodsAdapter.setOnItemClickListener(new GoodsItemClickListener());
        }else{
            leavePortWarehousingGoodsAdapter.updateAdapter(mainInfoDetailList , IsEditor);
        }

        // 已入库信息
        initWarehousingInfoAdapter();
    }

    /**
     * 已入库信息
     */
    private void initWarehousingInfoAdapter(){
        if(warehousingMainInfoList == null || warehousingMainInfoList.size() == 0) {
            warehousingMainInfoList = new ArrayList<>();
            warehousingMainInfoList.add(null);
        }

        if(warehousingMainInfoList.get(warehousingMainInfoList.size() -1) != null && IsEditor)
            warehousingMainInfoList.add(null);

        if(warehousingMainInfoAdapter == null) {
            warehousingMainInfoAdapter = new LevePortWarehousingInfoAdapter(mActivity, warehousingMainInfoList , IsEditor);
            mRlContainerInfo.setAdapter(warehousingMainInfoAdapter);
            mRlContainerInfo.setLayoutManager(new LinearLayoutManager(mActivity , RecyclerView.HORIZONTAL , false));

            warehousingMainInfoAdapter.setOnItemClickListener(onInfoClickListener);

            initWarehoused();
        }else {
            warehousingMainInfoAdapter.updateAdapter(warehousingMainInfoList,IsEditor);
        }
    }

    /**
     * 初始化当前航班的其他容器
     */
    private void initContainer() {
        mOtherGoodsContainerList = mWarehousingDetailData.getContainerList();

        if(mOtherGoodsContainerList != null && mOtherGoodsContainerList.size() != 0){
            String containerCode = "" ;

            for (int i = 0; i < mOtherGoodsContainerList.size(); i++) {
                if(TextUtils.isEmpty(containerCode)){
                    containerCode = mOtherGoodsContainerList.get(i).getCode();
                }else {
                    containerCode += "," + mOtherGoodsContainerList.get(i).getCode();
                }
            }

            if(IsEditor)
                AlertDialog.getInstance(mActivity)
                        .setContent("当前航班在库内已有" + mOtherGoodsContainerList.size()
                                + "斗货物，"
                                + (mOtherGoodsContainerList.size() == 1 ? "斗号为 : " : "斗号分别为 : ")
                                + containerCode + "，是否确定在已有斗中装货？")
                        .setConfirmButton(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if(mOtherGoodsContainerList.size() > 1) {
                                    TugDialog.getInstance(mActivity)
                                            .setTugData(mOtherGoodsContainerList)
                                            .setOnItemClickListener(new TugDialog.OnSheetItemClickListener() {
                                                @Override
                                                public void onClick(TugData channelData) {
                                                    ContainerType = channelData.getType();
                                                    mTvContainerType.setText(ContainerType == 1 ? R.string.text_tug : R.string.text_container);
                                                    initGoodsContainer(channelData);
                                                }
                                            })
                                            .show();
                                }else {
                                    ContainerType = mOtherGoodsContainerList.get(0).getType();
                                    mTvContainerType.setText(ContainerType == 1 ? R.string.text_tug : R.string.text_container);
                                    initGoodsContainer(mOtherGoodsContainerList.get(0));
                                }
                            }
                        }).show();
        }
    }

    /**
     * 初始化拖斗
     */
    private void initGoodsContainer(TugData tugData){
        mTugData = tugData ;
        mTvContainerNo.setText(mTugData.getCode());
        mTvContainerWeight.setText(String.valueOf(mTugData.getWeight()));

        mLlPalletNoContainer.setVisibility(ContainerType == 2 ? View.VISIBLE : View.GONE);

        mContainerWeight = mTugData.getWeight() + (mPalletData == null ? 0 : mPalletData.getWeight());
    }

    /**
     * 条目点击事件
     */
    private OnItemClickListener onInfoClickListener = new OnItemClickListener() {
        @Override
        public void onClick(View view, int position) {
            if(warehousingMainInfoList.get(position) == null){
                if(getInputInfo(true) != null){
                    if(clickInfoPosition == -1){
                        warehousingMainInfoList.add(warehousingMainInfoList.size() - 1 , getInputInfo(false));
                    }else {
                        warehousingMainInfoList.set(clickInfoPosition , getInputInfo(false));
                    }

                    clickInfoPosition = -1 ;
                    setInputInfo(null);
                }
            }else {
                if(clickInfoPosition != -1){
                    if(getInputInfo(true) != null) {
                        warehousingMainInfoList.set(clickInfoPosition, getInputInfo(false));

                        clickInfoPosition = position;
                        setInputInfo(warehousingMainInfoList.get(position));
                    }
                }else {
                    clickInfoPosition = position;
                    setInputInfo(warehousingMainInfoList.get(position));
                }
            }

            // 初始化入库信息
            initWarehoused();
            warehousingMainInfoAdapter.updateAdapter(warehousingMainInfoList , clickInfoPosition);
        }

        @Override
        public void onLongClick(View view, int position) {
            AlertDialog.getInstance(mActivity)
                    .setContent(R.string.dialog_remove_container_info)
                    .setConfirmButton(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if(position == clickInfoPosition) {
                                setInputInfo(null);
                                clickInfoPosition = -1 ;
                            }
                            warehousingMainInfoList.remove(position);
                            initWarehousingInfoAdapter();
                        }
                    }).show();
        }
    };

    /**
     * 货物输入框输入内容
     */
    private class GoodsEditorCallbackListener implements GoodsEditorActivity.EditorCallbackListener {
        @Override
        public void onSubmit(Bundle bundle) {
            int position = bundle.getInt(Constant.Position);

            mainInfoDetailList.get(position).setDetailNumber(bundle.getInt(Constant.Count));
            mainInfoDetailList.get(position).setDetailWeight(bundle.getDouble(Constant.Weight));
            mainInfoDetailList.get(position).setDetailLength(bundle.getDouble(Constant.Length));
            mainInfoDetailList.get(position).setDetailWidth(bundle.getDouble(Constant.Width));
            mainInfoDetailList.get(position).setDetailHeight(bundle.getDouble(Constant.Height));
            mainInfoDetailList.get(position).setVolume(bundle.getInt(Constant.Count) * bundle.getDouble(Constant.Width) * bundle.getDouble(Constant.Height) * bundle.getDouble(Constant.Length));

            // 初始化货物信息
            initGoodsAdapter();

            //判断是否全部入库
            initWarehoused();
        }
    }

    /**
     * 点击默认体积
     */
    private class GoodsItemTextClickListener implements OnTextClickListener{

        @Override
        public void onClick(View view, int position) {
            switch (view.getId()){
                case R.id.mIbDefaultVolume :
                    // 默认体积
                    mainInfoDetailList.get(position).setDetailLength(0.3);
                    mainInfoDetailList.get(position).setDetailWidth(0.2);
                    mainInfoDetailList.get(position).setDetailHeight(0.1);
                    mainInfoDetailList.get(position).setVolume(mainInfoDetailList.get(position).getDetailNumber() * 0.3 * 0.2 * 0.1);
                    break;
            }

            // 初始化货物信息
            initGoodsAdapter();
        }
    }

    /**
     * 点击货物
     */
    private class GoodsItemClickListener extends OnItemClickListener {
        @Override
        public void onClick(View view, int position) {
            // 新增
            mainInfoDetailList.add(mainInfoDetailList.size() - 1 , new MainInfoDetail());
            initGoodsAdapter();
        }

        @Override
        public void onLongClick(View view, int position) {
            if(!IsEditor)
                return;

            if(mainInfoDetailList.size() != 2) {
                // 删除
                AlertDialog.getInstance(mActivity)
                        .setContent(R.string.dialog_remove_goods_info)
                        .setConfirmButton(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mainInfoDetailList.remove(position);
                                initGoodsAdapter();
                                initWarehoused();
                            }
                        }).show();
            }else {
                ToastUtils.showToast(R.string.toast_goods_one);
            }
        }
    }

    /**
     * 赋值字段
     * @param mainInfoBean
     */
    private void setInputInfo(WarehousingMainInfoBean mainInfoBean){
        if(mainInfoBean == null){
            mChannelData = (mChannelDataList != null && mChannelDataList.size() != 0) ? mChannelDataList.get(0) : null;
            mTvCheckChannel.setText(mChannelData == null ? "" : mChannelData.getCode());
            mTvStorageArea.setText(mStorageAreaData == null ? "" : mStorageAreaData.getName());
            mTvGoodsWeight.setText("");
            mTvContainerWeight.setText("");
            mTvContainerType.setText(getString(R.string.text_tug));
            mTvContainerNo.setText("");
            mLlPalletNoContainer.setVisibility(View.GONE);
            mTvPalletNo.setText("");

            mGoodsWeight = 0 ;
            mTvGoodsWeight.setText(String.valueOf(CommonUtils.getDouble(mGoodsWeight)));

            mContainerWeight = 0 ;
            mTvContainerWeight.setText(String.valueOf(mContainerWeight));

            mGoodsTotalWeight = 0 ;
            mTvGoodsTotalWeight.setText(String.valueOf(mGoodsTotalWeight));

            // 初始化货物信息
            mainInfoDetailList = null ;
        }else {
            mChannelData = new ChannelData(mainInfoBean.getChannelId() , mainInfoBean.getChannelCode());
            mTvCheckChannel.setText(mChannelData.getCode());

            mTvStorageArea.setText(mainInfoBean.getWarehouseAreaName() == null ? "" : mainInfoBean.getWarehouseAreaName());
            mStorageAreaData = new StorageAreaData(mainInfoBean.getWarehouseAreaId() , mainInfoBean.getWarehouseAreaName());
            mTvStorageArea.setText(mStorageAreaData.getName());

            mTvGoodsWeight.setText(String.valueOf(mainInfoBean.getWeight()));

            mGoodsWeight = mainInfoBean.getWeight() ;
            mContainerWeight = mainInfoBean.getTransportWeight() + mainInfoBean.getPalletWeight();
            mGoodsTotalWeight = mainInfoBean.getWeight() + mainInfoBean.getTransportWeight() + mainInfoBean.getPalletWeight();

            mTvGoodsTotalWeight.setText(String.valueOf(mGoodsTotalWeight));

            ContainerType = mainInfoBean.getTransportType() ;
            mTvContainerType.setText(getString(ContainerType == 1 ? R.string.text_tug : (ContainerType == 2 ? R.string.text_container : R.string.text_custom)));

            mTvContainerNo.setText(mainInfoBean.getTransportCode() == null ? "" : mainInfoBean.getTransportCode());
            mTvContainerWeight.setText(String.valueOf(mainInfoBean.getTransportWeight()));

            if(ContainerType != 2) {
                mTugData = new TugData(mainInfoBean.getTransportCode(), mainInfoBean.getTransportWeight());
                mLlPalletNoContainer.setVisibility(View.GONE);
            }else {
                mContainerData = new ContainerData(mainInfoBean.getTransportCode(), mainInfoBean.getTransportWeight());

                mLlPalletNoContainer.setVisibility(View.VISIBLE);
                mTvPalletNo.setText(mainInfoBean.getPalletCode() == null ? "" : mainInfoBean.getPalletCode());
                mTvPalletWeight.setText(String.valueOf(mainInfoBean.getPalletWeight()));
                mPalletData = new TugData(mainInfoBean.getPalletCode() , mainInfoBean.getPalletWeight());
            }

            mainInfoDetailList = mainInfoBean.getDetailList();

            if(mainInfoDetailList == null || mainInfoDetailList.size() == 0) {
                MainInfoDetail mainInfoDetail = new MainInfoDetail();
                mainInfoDetail.setDetailNumber(mainInfoBean.getNum());
                mainInfoDetailList = new ArrayList<>();
                mainInfoDetailList.add(mainInfoDetail);
            }
        }
        initGoodsAdapter();
        // 初始化托板儿信息
        initWarehousingInfoAdapter();
    }

    private boolean isSubmit(){
        if(warehousingMainInfoList == null || warehousingMainInfoList.size() == 0)
            return true ;

        for (int i = 0; i < warehousingMainInfoList.size(); i++) {
            WarehousingMainInfoBean warehousingMainInfoBean = warehousingMainInfoList.get(i);

            if(warehousingMainInfoBean == null)
                continue;

            if(clickInfoPosition != i && TextUtils.isEmpty(warehousingMainInfoBean.getWarehouseAreaName())){
                ToastUtils.showToast("请选择编号为" + warehousingMainInfoBean.getTransportCode() + "拖斗的存放区域");
                return false ;
            }

            if(clickInfoPosition != i && warehousingMainInfoBean.getNum() == 0){
                ToastUtils.showToast("请输入编号为" + (i + 1) + "拖斗的货物件数");
                return false ;
            }

            if(clickInfoPosition != i && warehousingMainInfoBean.getWeight() < 0){
                ToastUtils.showToast("请输入编号为" + (i + 1) + "拖斗的货物重量为负数，请修改");
                return false ;
            }
        }

        return true ;
    }

    /**
     * 判断内容是否填写齐全
     * @return
     */
    private WarehousingMainInfoBean getInputInfo(boolean isToast){
        String checkChannel = mTvCheckChannel.getText().toString();
        String goodsWeight = mTvGoodsWeight.getText().toString();
        String storageArea = mTvStorageArea.getText().toString();
        String containerType = mTvContainerType.getText().toString();
        String containerNo = mTvContainerNo.getText().toString();
        String palletNo = mTvPalletNo.getText().toString();

        if(TextUtils.isEmpty(checkChannel)){
            if(isToast)
                ToastUtils.showToast(R.string.toast_weighbridge_route_null);
            return null ;
        }

        if(TextUtils.isEmpty(goodsWeight)){
            if(isToast)
                ToastUtils.showToast(R.string.toast_weight_null);
            return null ;
        }

        if(Double.parseDouble(goodsWeight) < 0){
            if(isToast)
                ToastUtils.showToast(R.string.toast_weight_negative);
            return null ;
        }

        if(TextUtils.isEmpty(storageArea)){
            if(isToast)
                ToastUtils.showToast(R.string.toast_storage_area_null);
            return null ;
        }

        if(TextUtils.isEmpty(containerType)){
            if(isToast)
                ToastUtils.showToast(R.string.toast_container_type_null);
            return null ;
        }

        if(TextUtils.isEmpty(containerNo)){
            if(isToast)
                ToastUtils.showToast(R.string.toast_container_no_null);
            return null ;
        }

        if(TextUtils.isEmpty(palletNo) && ContainerType == 2){
            if(isToast)
                ToastUtils.showToast(R.string.toast_pallet_no_null);
            return null;
        }

        int count = 0 ;
        int volume = 0 ;

        for (int i = 0; i < (mainInfoDetailList.contains(null) ? mainInfoDetailList.size() - 1 : mainInfoDetailList.size()); i++) {
            if(mainInfoDetailList.get(i).getDetailNumber() == 0){
                if(isToast)
                    ToastUtils.showToast("第" + (i + 1) + "票货物未填写件数");
                return null ;
            }else if(mainInfoDetailList.get(i).getDetailLength() == 0
                    || mainInfoDetailList.get(i).getDetailWidth() == 0
                    || mainInfoDetailList.get(i).getDetailHeight() == 0){
                if(isToast)
                    ToastUtils.showToast("第" + (i + 1) + "票货物未填写体积");
                return null;
            }

            count += mainInfoDetailList.get(i).getDetailNumber();

            volume += mainInfoDetailList.get(i).getVolume();
        }

        WarehousingMainInfoBean bean = new WarehousingMainInfoBean();
        bean.setChannelId(mChannelData.getId());
        bean.setChannelCode(mChannelData.getCode());
        bean.setWarehouseAreaId(mStorageAreaData.getId());
        bean.setWarehouseAreaName(mStorageAreaData.getName());
        bean.setTransportType(ContainerType == 3 ? 1 : ContainerType);
        if(ContainerType != 2) {
            bean.setTransportCode(mTugData.getCode());
            bean.setTransportWeight(mTugData.getWeight());
        }else {
            bean.setTransportCode(mContainerData.getCode());
            bean.setTransportWeight(mContainerData.getWeight());
            bean.setPalletCode(mPalletData.getCode());
            bean.setPalletWeight(mPalletData.getWeight());
        }
        bean.setWeight(Double.parseDouble(goodsWeight));
        bean.setNum(count);
        bean.setVolume(volume);

        if(mainInfoDetailList != null)
            if(mainInfoDetailList.contains(null)) {
                bean.setDetailList(mainInfoDetailList.subList(0, mainInfoDetailList.size() - 1));
            }else {
                bean.setDetailList(mainInfoDetailList);
            }

        return bean ;
    }

    /**
     * 判断是否全部入库(件数不小于运单件数就为全部入库)
     */
    private void initWarehoused(){
        int warehousedCount = 0 ;
        double warehousedWeight = 0 ;

        if(warehousingMainInfoList != null && warehousingMainInfoList.size() != 0)
            for (int i = 0; i < warehousingMainInfoList.size() ; i++) {
                if(warehousingMainInfoList.get(i) == null)
                    continue;

                warehousedCount += warehousingMainInfoList.get(i).getNum();
                warehousedWeight += warehousingMainInfoList.get(i).getWeight();
            }

        // 赋值容器重量，净重，总重
        if(isBridgeWight){
            mGoodsWeight = mGoodsTotalWeight - mContainerWeight ;
        }else if(mGoodsWeight != 0){
            mGoodsTotalWeight = mContainerWeight + mGoodsWeight;
        }

        if(mGoodsTotalWeight != 0)
            mTvGoodsTotalWeight.setText(String.valueOf(mGoodsTotalWeight));

        mTvGoodsWeight.setText(String.valueOf(CommonUtils.getDouble(mGoodsWeight)));
        mTvGoodsWeight.setTextColor(getColor(mGoodsWeight < 0 ? R.color.color_red : R.color.text_color));

        mLlWarehousedContainer.setBackground(getDrawable(warehousedCount == mOrderDetail.getNum() ? R.drawable.shape_green : (warehousedCount > mOrderDetail.getNum() ? R.drawable.shape_red_10 : R.drawable.shape_yellow_10)));
        mTvWarehoused.setTextColor(getColor(warehousedCount < mOrderDetail.getNum() ? R.color.color_blue : R.color.white));
        mTvWarehousedText.setTextColor(getColor(warehousedCount < mOrderDetail.getNum() ? R.color.color_blue : R.color.white));

        mTvWarehoused.setText(warehousedCount + " 件 / " + warehousedWeight + " KG");
    }

    @Override
    public void onClick(View v) {
        if(CommonUtils.isFastDoubleClick())
            return;

        switch (v.getId()){
            case R.id.mTvCheckChannel:
                // 地磅通道
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                ChanelDialog.getInstance(LeavePortWarehousingDetailsActivity.this)
                        .getChannelData(mOrderDetail.getState() == Constant.PULL_OFF ? Constant.Leave_All : Constant.LeavePortWarehousing)
                        .setOnItemClickListener(new ChanelDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(ChannelData channelData) {
                                mChannelData = channelData;
                                mTvCheckChannel.setText(channelData.getName());
                                initWarehoused();
                            }
                        }).show();
                break;
            case R.id.mTvStorageArea:
                // 存放区域
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                StorageAreaDialog.getInstance(mActivity , Constant.LeavePortStorage)
                        .setSingleSelect(true)
                        .setSelectedArea(mStorageAreaData)
                        .setConfirmButton(new StorageAreaDialog.OnStorageOnClickListener() {
                            @Override
                            public void onClick(List<StorageAreaData> storageAreaList) {
                                mStorageAreaData = storageAreaList.get(0);
                                mTvStorageArea.setText(mStorageAreaData.getName());
                                initWarehoused();
                            }
                        })
                        .show();
                break;
            case R.id.mTvContainerType:
                // 容器类型
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                BottomDialog.getInstance(mActivity)
                        .addSheetItem(ConstantInfo.ContainerList)
                        .setOnItemClickListener(new OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                mTvContainerType.setText(ConstantInfo.ContainerList.get(which));

                                ContainerType = which + 1;
                                mTugData = null ;
                                mPalletData = null ;
                                mContainerWeight = 0 ;
                                mTvContainerNo.setText("");
                                mTvContainerWeight.setText("");
                                mTvPalletNo.setText("");
                                mTvPalletWeight.setText("");
                                mLlPalletNoContainer.setVisibility(ContainerType == 2 ? View.VISIBLE : View.GONE);

                                if(which == 2){
                                    CustomContainerEditorActivity.openActivity(mActivity, new CustomContainerEditorActivity.EditorCallbackListener() {
                                        @Override
                                        public void onSubmit(Bundle bundle) {
                                            mTugData = new TugData(bundle.getString(Constant.Number) , bundle.getDouble(Constant.Weight));
                                            mTvContainerNo.setText(mTugData.getCode());
                                            mTvContainerWeight.setText(String.valueOf(mTugData.getWeight()));

                                            mContainerWeight = mTugData.getWeight() + (mPalletData == null ? 0 : mPalletData.getWeight());
                                        }
                                    } , false);
                                }
                            }
                        }).show();
                break;
            case R.id.mTvContainerNo:
                // 容器编号
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                if(ContainerType == 2){
                    clickContainer();
                }else {
                    TugDialog.getInstance(mActivity)
                            .setTugType(0)
                            .setOnItemClickListener(new TugDialog.OnSheetItemClickListener() {
                                @Override
                                public void onClick(TugData tugData) {
                                    initGoodsContainer(tugData);

                                    initWarehoused();
                                }
                            }).show();
                }
                break;
            case R.id.mTvPalletNo:
                // 托盘
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                TugDialog.getInstance(mActivity)
                        .setTugType(1)
                        .setOnItemClickListener(new TugDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(TugData tugData) {
                                mPalletData = tugData;
                                mTvPalletNo.setText(mPalletData.getCode());
                                mTvPalletWeight.setText(String.valueOf(mPalletData.getWeight()));

                                mContainerWeight = mPalletData.getWeight() + (ContainerType == 2 ? (mContainerData == null ? 0 : mContainerData.getWeight()) : (mTugData == null ? 0 : mTugData.getWeight()));

                                initWarehoused();
                            }
                        }).show();
                break;
            case R.id.mIbBridgeWeigh :
                // 获取地磅通道重量
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                if(mChannelData == null){
                    ToastUtils.showToast(R.string.toast_weighbridge_route_null);
                    return;
                }

                if((ContainerType != 2 && mTugData == null) || (ContainerType == 2 && mContainerData == null)){
                    ToastUtils.showToast(R.string.toast_container_no_null);
                    return;
                }

                if(mPalletData == null && ContainerType == 2){
                    ToastUtils.showToast(R.string.toast_pallet_no_null);
                    return ;
                }

                NetworkUtils.getBridgeWeigh(new OkGoBackListener(mActivity) {
                    @Override
                    public void onSuccess(Object body) {
                        mGoodsTotalWeight = (Double)body ;
                        isBridgeWight = true ;
                        initWarehoused();
                    }
                }, mChannelData.getCode());
                break;
            case R.id.mTvGoodsWeight:
                // 重量
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                EditorActivity.openActivity(mActivity, new EditorActivity.EditorCallbackListener() {
                    @Override
                    public void onSubmit(String content) {
                        mGoodsWeight = TextUtils.isEmpty(content) ? 0 : Double.parseDouble(content);

                        isBridgeWight = false;
                        initWarehoused();
                    }
                } , mTvGoodsWeight.getText().toString());
                break;
            case R.id.mIbStorageAreaNFC:
                // 区域NFC
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                turnNfcAct(R.string.text_storage_area , Constant.Leave_Port_Area);
                break;
            case R.id.mIbContainerNoNFC:
                // 容器编号NFC
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                turnNfcAct(R.string.text_container_no , Constant.Port_Tug);
                break;
            case R.id.mIbPalletNoNFC:
                // 托盘编号
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                turnNfcAct(R.string.text_pallet_no , Constant.Port_Pallet);
                break;
            case R.id.mBtnSubmit:
                // 提交
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                if(getInputInfo(true) == null)
                    return;

                if(!isSubmit())
                    return;

                if(IsSaveIng){
                    ToastUtils.showToast(R.string.toast_save_ing);
                    return;
                }

                AlertDialog.getInstance(mActivity)
                        .setContent(R.string.dialog_confirm_submit_warehousing_info)
                        .setConfirmButton(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                clickSubmit(true);
                            }
                        }).show();
                break;
            case R.id.mBtnSave:
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                if(getInputInfo(true) == null)
                    return;

                if(!isSubmit())
                    return;

                if(IsSaveIng){
                    ToastUtils.showToast(R.string.toast_save_ing);
                    return;
                }

                AlertDialog.getInstance(mActivity)
                        .setContent(R.string.dialog_confirm_save_warehousing_info)
                        .setConfirmButton(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                clickSubmit(false);
                            }
                        }).show();
                break;
            case R.id.mBtnRevise:
                // 修改
                if(mWarehousingDetailData == null){
                    ToastUtils.showToast(R.string.toast_storeroom_inventory_data_null);
                    return;
                }

                IsEditor = true ;
                initLocationData();
                break;
            case R.id.mIbBack:
                // 返回
                onBackPressed();
                break;
        }
    }

    private void clickContainer(){
        ContainerDialog.getInstance(mActivity)
                .setOnItemClickListener(new ContainerDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(ContainerData containerData) {
                        if(containerData == null){
                            CustomContainerEditorActivity.openActivity(mActivity, new CustomContainerEditorActivity.EditorCallbackListener() {
                                @Override
                                public void onSubmit(Bundle bundle) {
                                    setContainerData(bundle);
                                }
                            } , true);
                        }else {
                            mContainerData = containerData;
                            mTvContainerNo.setText(mContainerData.getCode());
                            mTvContainerWeight.setText(String.valueOf(mContainerData.getWeight()));

                            mContainerWeight = mContainerData.getWeight() + (mPalletData == null ? 0 : mPalletData.getWeight());

                            initWarehoused();
                        }
                    }

                    @Override
                    public void onLongClick(ContainerData containerData) {
                        CustomContainerEditorActivity.openActivity(mActivity, new CustomContainerEditorActivity.EditorCallbackListener() {
                            @Override
                            public void onSubmit(Bundle bundle) {
                                resetContainerData(bundle , containerData);
                            }
                        } , containerData);
                    }
                }).show();
    }

    /**
     * 设置集装器数据
     * @param mBundle
     */
    private void setContainerData(Bundle mBundle){
        mContainerData = new ContainerData(mBundle.getString(Constant.Number));
        mContainerData.setWeight(mBundle.getDouble(Constant.Weight));
        mContainerData.setFlightNo(mOrderDetail.getFlightNo());
        mContainerData.setDateEntryAndExit(mOrderDetail.getFldt());
        mContainerData.setDeap(mOrderDetail.getDeap());
        mContainerData.setFlightId(mOrderDetail.getFlightId());
        mContainerData.setFldt(mOrderDetail.getFldt());

        List<ContainerData> containerDataList = new ArrayList<>();
        containerDataList.add(mContainerData);

        NetworkUtils.addContainer(new OkGoBackListener(mActivity) {
            @Override
            public void onSuccess(Object body) {
                mTvContainerNo.setText(mContainerData.getCode());
                mTvContainerWeight.setText(String.valueOf(mContainerData.getWeight()));

                mContainerWeight = mContainerData.getWeight() + (mPalletData == null ? 0 : mPalletData.getWeight());
            }
        }, containerDataList);
    }

    /**
     * 设置集装器数据
     * @param mBundle
     */
    private void resetContainerData(Bundle mBundle , ContainerData containerData){
        containerData.setCode(mBundle.getString(Constant.Number));
        containerData.setWeight(mBundle.getDouble(Constant.Weight));
        containerData.setFlightNo(mOrderDetail.getFlightNo());
        containerData.setDateEntryAndExit(mOrderDetail.getFldt());
        containerData.setDeap(mOrderDetail.getDeap());

        NetworkUtils.resetContainer(new OkGoBackListener(mActivity) {
            @Override
            public void onSuccess(Object body) {
                clickContainer();
            }
        }, containerData);
    }

    private void turnNfcAct(int resource , int turnType){
        mIntent = new Intent(mActivity , NFCActivity.class);
        mBundle = new Bundle();
        mBundle.putInt(Constant.TurnType , turnType);
        mBundle.putString(Constant.Title , getString(resource));
        mIntent.putExtras(mBundle);
        turnActForResult(mIntent);
    }

    /**
     * 点击提交
     */
    private void clickSubmit(boolean isSave) {
        if(getInputInfo(true) != null){
            // 初始化入库信息
            initWarehoused();

            if(clickInfoPosition == -1){
                if(warehousingMainInfoList == null){
                    warehousingMainInfoList = new ArrayList<>();
                    warehousingMainInfoList.add(0 , getInputInfo(false));
                } else {
                    if(warehousingMainInfoList.size() == 0){
                        warehousingMainInfoList.add(getInputInfo(false));
                    }else {
                        warehousingMainInfoList.add(warehousingMainInfoList.size() - 1 , getInputInfo(false));
                    }
                }
            }else {
                warehousingMainInfoList.set(clickInfoPosition , getInputInfo(false));
            }
        }

        mWarehousingDetailData.setOutwardStorageData(mOrderDetail);
        mWarehousingDetailData.setMainList(warehousingMainInfoList);

        warehousingMainInfoList.remove(null);

        for (int i = 0; i < warehousingMainInfoList.size(); i++) {
            if(warehousingMainInfoList.get(i) == null)
                continue;

            warehousingMainInfoList.get(i).setVolume(0);
            if(warehousingMainInfoList.get(i).getOrderDetailId() == 0)
                warehousingMainInfoList.get(i).setOrderDetailId(mOrderDetail.getOutwardOrderDetailId());

            if(warehousingMainInfoList.get(i).getDetailList() == null)
                continue;

            if(warehousingMainInfoList.get(i).getDetailList().contains(null))
                warehousingMainInfoList.get(i).getDetailList().remove(null);

            for (int j = 0; j < warehousingMainInfoList.get(i).getDetailList().size(); j++) {
                warehousingMainInfoList.get(i).setVolume(warehousingMainInfoList.get(i).getVolume() + warehousingMainInfoList.get(i).getDetailList().get(j).getVolume());
            }
        }

        if(mOrderDetail.getNum() == 1
                && mWarehousingDetailData.getMainList().size() == 1
                && mWarehousingDetailData.getMainList().get(0).getDetailList().size() == 1
                && mWarehousingDetailData.getMainList().get(0).getDetailList().get(0).getDetailNumber() == 1){
            MainInfoDetail mainInfoDetail = mWarehousingDetailData.getMainList().get(0).getDetailList().get(0);
            //TODO 地板承受力
        }

        mWarehousingDetailData.setSave(isSave);
        IsSaveIng = true;
        NetworkUtils.saveLeavePortWarehousingDetails(new OkGoBackListener(mActivity) {
            @Override
            public void onSuccess(Object body) {
                IsSaveIng = false;
                ToastUtils.showToast(isSave ? R.string.toast_submit_success : R.string.toast_save_success);
                ToastUtils.showToast(R.string.toast_submit_success);
                onFinishResult();
            }

            @Override
            public void onError() {
                IsSaveIng = false;
            }
        }, JsonUtils.parseBeanToJson(mWarehousingDetailData));
    }

    @Override
    protected void initRefresh(int count) {
        super.initRefresh(count);

        NetworkUtils.checkPageLock(new OkGoBackListener(mActivity) , ConstantInfo.OUT_STORAGE_IN , mOrderID);
    }

    private boolean IsTure ;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == Constant.REQUEST_CODE && resultCode == Constant.RESULT_NFC_CODE){
            mBundle = data.getExtras();

            NfcBean nfcBean = (NfcBean) mBundle.getSerializable(Constant.INFO);

            switch (mBundle.getInt(Constant.TurnType)){
                case Constant.Leave_Port_Area :
                    // 出港区域
                    if(nfcBean.getType() == Constant.Leave_Port_Area){
                        NetworkUtils.getStorageAreaList(new OkGoBackListener(mActivity){
                            @Override
                            public void onSuccess(Object body) {
                                List<StorageAreaData> dataList = (List<StorageAreaData>) body;
                                IsTure = false ;

                                for (int i = 0; i < dataList.size(); i++) {
                                    if(dataList.get(i).getId() == nfcBean.getId() && dataList.get(i).getName().equals(nfcBean.getCode())) {
                                        IsTure = true;
                                        mStorageAreaData = dataList.get(i);
                                    }
                                }

                                if(IsTure){
                                    mTvStorageArea.setText(nfcBean.getCode());
                                }else {
                                    ToastUtils.showToast(R.string.toast_leave_port_area_error);
                                }
                            }
                        } , Constant.LeavePortStorage);
                    } else {
                        ToastUtils.showToast(R.string.toast_leave_port_area_error);
                    }
                    break;
                case Constant.Port_Tug:
                    // 出港拖斗编号
                    if(nfcBean.getType() == Constant.Port_Tug){
                        NetworkUtils.getTugList(new OkGoBackListener(mActivity){
                            @Override
                            public void onSuccess(Object body) {
                                List<TugData> dataList = (List<TugData>) body;
                                IsTure = false ;

                                for (int i = 0; i < dataList.size(); i++) {
                                    if(dataList.get(i).getId() == nfcBean.getId() && dataList.get(i).getCode().equals(nfcBean.getCode())) {
                                        IsTure = true;
                                        mTugData = dataList.get(i);
                                    }
                                }

                                if(IsTure){
                                    mTvContainerNo.setText(mTugData.getCode());
                                    mTvContainerWeight.setText(String.valueOf(mTugData.getWeight()));
                                }else {
                                    ToastUtils.showToast(R.string.toast_leave_port_tug_error);
                                }
                            }
                        } , 0);
                    } else {
                        ToastUtils.showToast(R.string.toast_leave_port_tug_error);
                    }
                    break;
                case Constant.Port_Pallet:
                    // 出港托盘
                    if(nfcBean.getType() == Constant.Port_Pallet){
                        NetworkUtils.getTugList(new OkGoBackListener(mActivity){
                            @Override
                            public void onSuccess(Object body) {
                                List<TugData> dataList = (List<TugData>) body;
                                IsTure = false ;

                                for (int i = 0; i < dataList.size(); i++) {
                                    if(dataList.get(i).getId() == nfcBean.getId() && dataList.get(i).getCode().equals(nfcBean.getCode())) {
                                        IsTure = true;
                                        mPalletData = dataList.get(i);
                                    }
                                }

                                if(IsTure){
                                    mTvPalletNo.setText(mTugData.getCode());
                                    mTvPalletWeight.setText(String.valueOf(mTugData.getWeight()));
                                }else {
                                    ToastUtils.showToast(R.string.toast_leave_port_pallet_error);
                                }
                            }
                        } , 1);
                    } else {
                        ToastUtils.showToast(R.string.toast_leave_port_pallet_error);
                    }
                    break;
            }
        }
    }
}
